import bcryptjs from 'bcryptjs'

const {BCRYPT_SALT_ROUNDS} = process.env

/**
 * @author: ares
 * @date: 2025/7/3 上午10:47
 * @description: 加密
 * @param code
 * @returns {string}
 */
export function encrypt(code: string) {
  return bcryptjs.hashSync(code, Number(BCRYPT_SALT_ROUNDS))
}

/**
 * @author: ares
 * @date: 2025/7/3 上午10:48
 * @description: 比较明文和密文
 * @param code
 * @param hash
 * @returns {boolean}
 */
export function compare(code: string, hash: string) {
  return bcryptjs.compareSync(code, hash)
}
